
package bankservice.endpoint;

import java.util.concurrent.Semaphore;

/*import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(endpointInterface = "bankservice.endpoint.BankAccountInterface")*/

public class BankAccountImpl implements  BankAccountInterface {
	
	private String accountNumber;
	private String accountHolder;
	private String address;
	
	private float balance;
	private float tempTransferAmount;
	
	private Semaphore sema;

	public void BankAccountInterface() {}

    public BankAccountImpl() {
	
    	accountNumber = "" ;
    	accountHolder = "";
    	address = "Hutchison Street";
    	balance = 1000;

       	sema = new Semaphore(1, true);
   	}
 
        //@WebMethod() 
   	public String getAccountNumber()  {
		
		return accountNumber;	
	}

 //       @WebMethod()
	public void setAccountNumber(String accNum) {
		
		accountNumber = accNum;		
        }

    //    @WebMethod()	
	public String getAccountHolder() {
		
		return accountHolder;	
        }

        //@WebMethod()
	public void setAccountHolder(String accHolder) {
		
		accountHolder = accHolder;		
        }
	
        //@WebMethod()
	public String getAddress(){
		
		return address;	
        }

        //@WebMethod()
	public void setAddress(String accHolderAddress) {
		
		address = accHolderAddress;		
        }


        //@WebMethod()	
	public float getBalance(String accountNumber){
		
			return balance - tempTransferAmount;	
	}

        //@WebMethod()	
	public void setBalance(float accountBalance){
				
		balance = accountBalance;				
	}
	
		//@WebMethod()
	public void setTempTransferAmount(float amount){
		
		sema.acquireUninterruptibly();
		tempTransferAmount = amount;
		sema.release();				
	}

        //@WebMethod()
	public void deposite(String accountNumber, float amount) {
					
		sema.acquireUninterruptibly();
		balance = balance + amount;
		sema.release();
				
	}

        //@WebMethod()
	public void withdraw(String accountNumber, float amount){
						
		sema.acquireUninterruptibly();
		if (balance >= amount){
			balance = balance - amount;			
		}
		sema.release();
	}
}





